package day11;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author oldliu
 * @since 1.0
 */
//银行账号
public class Bank implements Comparable<Bank>, Serializable {
    private String no;//账号
    private String name;
    private String idcard;
    private String city;
    private float money;//余额

    public Bank() {
    }

    //这是private
    private Bank(String no, String name, float money) {
        this.no = no;
        this.name = name;
        this.money = money;
    }

    public Bank(String no, String name, String idcard, String city, float money) {
        this.no = no;
        this.name = name;
        this.idcard = idcard;
        this.city = city;
        this.money = money;
    }

    private void setCardAndMoney(String c,float m){
        this.idcard=c;
        this.money=m;
    }
    public String getNo() {
        return no;
    }

    public void setNo(String no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIdcard() {
        return idcard;
    }

    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public float getMoney() {
        return money;
    }

    public void setMoney(float money) {
        this.money = money;
    }

//    @Override//账号no相同，则认为账号相同
//    public boolean equals(Object obj) {
//        if (obj instanceof Bank) {
//            Bank b = (Bank) obj;
//            if(this.no==null) {
//                if(b.getNo()==null)
//                    return true;
//            }
//            else{
//                return this.no.equals(b.getNo());
//            }
//        }
//        return false;
//    }
//
//    @Override
//    public int hashCode() {
//        //no来比较，no来算hashCode...
//        return no==null?0:no.hashCode();
//    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Bank bankAcc = (Bank) o;
        return Objects.equals(no, bankAcc.no);
    }
    @Override
    public int hashCode() {
        return Objects.hash(no);
    }

    @Override
    public String toString() {
        return "账号{" +
                "no='" + no + '\'' +
                ", name='" + name + '\'' +
                ", idcard='" + idcard + '\'' +
                ", city='" + city + '\'' +
                ", money=" + money +
                '}';
    }

    //定BankAcc比较的规则：用账户的钱作为比较规则
//    @Override
//    public int compareTo(Object o) {
//        if(o instanceof Bank){
//            Bank a= (Bank) o;
//            //改成账户号的比较
//            //return this.no.compareTo(a.no);
//            //改成名字的unicode顺序
//            //return this.name.compareTo(a.name);
//            return (int)(this.money-a.money);
//        }
//        return 0;
//    }

    @Override
    public int compareTo(Bank o) {
        return (int)(this.money-o.money);
    }
}
